<template>
  <div class="top">
    <div class="top-text">
      <!-- <a-button type="primary">
      Primary
      </a-button> -->
      <!-- <a-menu v-model="current" mode="horizontal">
      </a-menu> -->
      <el-menu :default-active="activeIndex" class="default-head" mode="horizontal">
        <component
          v-for="(item,index) in menuBox"
          :key="index"
          :is="item.el"
          :index="item.key"
          @click="onPath(item)"
        >
          <template v-if="item.el === 'el-submenu'" slot="title">{{ item.label }}</template>
          <span v-else>{{ item.label }}</span>
          <component
            v-for="subitem in item.children"
            :key="subitem.key"
            :is="subitem.el"
            :index="subitem.key"
            @click.native.stop="onPath(subitem)"
          >{{ subitem.title }}</component>
        </component>
      </el-menu>
      <slot name="aaa" />
      <span class="drawer-menu" @click="minNav" style="color: #666"><i class="el-icon-menu"></i></span>
    </div>
  </div>
</template>
<script>
import { menuList } from '@/utils/menu.js'
export default {
  props: {
    cur: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      current: ['前端文档'],
      menuBox: menuList,
      activeIndex: '1'
    }
  },
  mounted() {
    // console.log(fun.func('1'),123)
  },
  methods: {
    // 回首页
    goHome(e) {
      if (e != this.$route.path) {
        this.$router.push({
          path: e.trim()
        })
      }
    },
    onPath(item) {
      window.open(`${window.location.origin}/#/${item.path}`,'_top')
    },
    minNav() {
      this.$emit('show-nav');
    }
  }
}
</script>
<style lang="scss" scoped>
.top {
  height: 56px;
  background: #fff;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  flex: 0 0 56px;
  position: sticky;
  top: 0;
  z-index: 9;
  box-shadow: 0 1px 4px 0 rgba(0,21,41, 0.12);
  .top-text {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    cursor: pointer;
    color: #333;
    padding-left: 10px;
    padding-right: 10px;
    box-sizing: border-box;
    display: flex;
    justify-content: space-between;
    align-items: center;
    span{
      font-size: 14px;
      &.cur{
        color: #409EFF;
      }
    }
  }
}
.drawer-menu{
  display: block;
  font-size: 24px;
  margin-right: 10px;
}
@media only screen and (min-width: 768px) {
  .drawer-menu{
    display: none;
  }
}
::v-deep {
  .default-head{
    height: 100%;
    width: 100%;
    position: relative;
    border-bottom: 0;
    box-sizing: border-box;
    &.el-menu--horizontal{
      border-bottom: 0;
    }
    .el-menu-item{
      height: 50px;
      line-height: 50px;
      color: #333;
      background-color: transparent;
      &:hover{
        text-decoration-line: underline;
        color: #409EFF;
        background-color: transparent;
      }
      &.is-active{
        border-bottom: 0;
      }
    }
    .el-submenu{
      height: 50px;
      line-height: 50px;
      .el-submenu__title{
        height: 50px;
        line-height: 50px;
        background-color: transparent;
        color: #333;
        &:hover{
          text-decoration-line: underline;
          color: #409EFF;
          background-color: transparent;
        }
      }
      &.is-active{
        border-bottom: 0;
        .el-submenu__title{
          border-bottom: 0;
        }
      }
    }
  }
}
</style>